package edu.kust.wangyiyun.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.kust.wangyiyun.common.Result;
import edu.kust.wangyiyun.entity.Review;
import edu.kust.wangyiyun.mapper.ReviewDtoMapper;
import edu.kust.wangyiyun.mapper.ReviewMapper;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @Author: Hxianfei
 * @CreateTime: 2024-09-02  20:57
 * @Description:
 */
@Service

public class ReviewService extends ServiceImpl<ReviewMapper, Review> {


    @Resource
    private ReviewDtoMapper reviewDtoMapper;

//    public List<Review> getReview(int productId) {
//        QueryWrapper<Review> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("product_id",productId);
//        List<Review> reviews = list(queryWrapper);
//        log.info("ReviewService.getReview: "+reviews);
//        return reviews;
//
//
//    }

    public Result selectByProductId(Integer productId) {
//        boolean flag = reviewDtoMapper.selectByProductId(productId).isEmpty();
//        if (flag) return Result.error("404","该商品暂无评论");
        return Result.success(reviewDtoMapper.selectByProductId(productId));

    }
}
